
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> ##########################################################################################################
> #Replication Files for Housing Discrimination and the Toxics Exposure Gap in the United States: 
> #Evidence from the Rental Market  by Peter Christensen, Ignacio Sarmiento-Barbieri and Christopher Timmins
> ##########################################################################################################
> 
> #Clean the workspace
> rm(list=ls())
> cat("\014")
> local({r <- getOption("repos"); r["CRAN"] <- "http://cran.r-project.org"; options(repos=r)}) #set repo
> 
> 
> #Load Packages
> pkg<-c("haven","dplyr","ggplot2","ggthemes","stringr","lubridate")
> lapply(pkg, require, character.only=T)
Loading required package: haven
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Loading required package: ggplot2
Loading required package: ggthemes
Loading required package: stringr
Loading required package: lubridate

Attaching package: ‘lubridate’

The following objects are masked from ‘package:dplyr’:

    intersect, setdiff, union

The following objects are masked from ‘package:base’:

    date, intersect, setdiff, union

[[1]]
[1] TRUE

[[2]]
[1] TRUE

[[3]]
[1] TRUE

[[4]]
[1] TRUE

[[5]]
[1] TRUE

[[6]]
[1] TRUE

> rm(pkg)
> 
> 
> dta3<-read_dta("../stores/toxic_discrimination_data.dta")
> 
> dta3<-dta3 %>% filter(sample==1)
> dta3$timestamp_response_received<-as.character(dta3$timestamp_response_received)
> 
> 
> dta3$response_time<-str_remove(dta3$timestamp_response_received,".[0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]")
> dta3$response_time<-str_replace(dta3$response_time,"T"," ")
> dta3$response_time<-ymd_hms(dta3$response_time)
> dta3$timestamp_inquiry_sent_out<-mdy_hm(dta3$timestamp_inquiry_sent_out)
> 
> dta3$response_days<-dta3$response_time-dta3$timestamp_inquiry_sent_out
> 
> dta3$response_days<-as.numeric(dta3$response_days,units="days")
> 
> 
> colors <- tibble::deframe(ggthemes::ggthemes_data[["fivethirtyeight"]])
> base_size = 4
> base_family = "sans"
> dta4<-dta3 %>% filter(response_days>=0,response_days<8)
> dta4 <- dta4 %>% mutate(hours=ifelse(response_days<=0.3,1,0),
+                         day=ifelse(response_days<=1,1,0),
+                         five_days=ifelse(response_days<=5,1,0))
> 
> prop.table(table(dta4$hours))

       0        1 
0.477467 0.522533 
> prop.table(table(dta4$day))

        0         1 
0.2544678 0.7455322 
> prop.table(table(dta4$five_days))

         0          1 
0.02097902 0.97902098 
> 
> ggplot(dta4,aes(x=response_days)) +
+   geom_histogram( colour="black", fill=colors["Medium Gray"], binwidth = .3) + #
+   scale_x_continuous("Days between inquiry and response",breaks=c(0,1,2,3,4,5,6,7,8)) +
+   ylab("Counts") +
+   theme_bw() +
+   theme_fivethirtyeight() + scale_color_fivethirtyeight("cyl") +
+   theme(legend.title= element_blank() ,
+         legend.position="none",
+         legend.justification=c(1,1),
+         legend.direction="vertical",
+         legend.box="horizontal",
+         legend.box.just = c("top"),
+         legend.background = element_rect(fill='transparent'),
+         axis.text.x =element_text( angle=0),
+         rect = element_rect(colour = "transparent", fill = "white"),
+         axis.title = element_text(), plot.margin = unit(c(2,2,1,1), "lines"))
> ggsave(filename="../views/figA5.png", height = 4, width = 6)
> 
> proc.time()
   user  system elapsed 
  1.284   0.140   1.462 
